import 'package:baselib/utils/image_util.dart';
import 'package:baselib/widgets/comm_app_bar.dart';
import 'package:baselib/widgets/comm_textfield.dart';
import 'package:baselib/widgets/form_input_widget.dart';
import 'package:baselib/widgets/gradient_card_view.dart';
import 'package:baselib/widgets/gradient_text_widget.dart';
import 'package:baselib/widgets/inkwell_button.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:framelib/utils/color_util.dart';
import 'package:framelib/utils/drawable_util.dart';
import 'package:framelib/utils/px_util.dart';
import 'package:framelib/utils/string_util.dart';
import 'package:framelib/widgets/comm_widget_manager.dart';
import 'package:framelib/widgets/main_gradient_button.dart';
import 'package:framelib/widgets/page_widget.dart';
import 'package:get/get.dart';
import 'package:module_business/module_my/viewmodel/edit_signature_view_model.dart';
import 'package:module_business/module_index/viewmodel/report_view_model.dart';
/**
 * 举报主页
 */
class ReportPage extends GetWidget<ReportViewModel> {
  const ReportPage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return PageWidget.build(
        builder: (ReportViewModel model){
          return PageWidget.PageScaffoldWidget(
            isShowBg: true,
            appBar: CommAppBar(
              backgroundColor: ColorUtil.instance.color_transparent,
              titleStr: StringUtil.instance.Report,
              titleTextStyle: TextStyle(
                fontSize: PxUtil.instance.px_18,
                color: ColorUtil.instance.color_white,
                fontWeight: FontWeight.bold
              ),
            ),
            body: ListView(
              shrinkWrap: true,
              children: [
                //选择项
                GridView.builder(
                    physics: NeverScrollableScrollPhysics(),
                    shrinkWrap: true,
                    padding: EdgeInsets.only(
                      left: PxUtil.instance.px_15,
                      right: PxUtil.instance.px_15,
                      top: PxUtil.instance.px_10,
                      bottom: PxUtil.instance.px_10,
                    ),
                    gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                        crossAxisCount: PxUtil.instance.px_2.toInt(),
                        mainAxisSpacing: PxUtil.instance.px_12,
                        crossAxisSpacing: PxUtil.instance.px_12,
                        childAspectRatio: (PxUtil.instance.screenWidth -
                            (PxUtil.instance.px_15 * 2) -
                            PxUtil.instance.px_15) /
                            (2 * PxUtil.instance.px_32)),
                    itemCount: model.reportTags?.length ?? 0,
                    itemBuilder: (BuildContext context, int index) {
                      return Obx(() => InkWellButton(
                        onPressed: ()=>model.tagItemTap(index),
                        child: _buildTagItemUi(model, index),
                      ));
                    }),

                //文本框
                Container(
                  child: GradientCardView(
                    elevation: PxUtil.instance.px_0,
                    margin: EdgeInsets.only(
                      left: PxUtil.instance.px_15,
                      right: PxUtil.instance.px_15,
                      top: PxUtil.instance.px_12,
                    ),
                    borderRadius: BorderRadius.circular(PxUtil.instance.px_10),
                    child: Container(
                      decoration: BoxDecoration(
                        color: ColorUtil.instance.color_2F4072,
                        borderRadius: BorderRadius.circular(PxUtil.instance.px_10),
                      ),
                      child: FormInputWidget(
                        title: '',
                        fontColor: ColorUtil.instance.color_white,
                        contentPadding: EdgeInsets.only(
                          left: PxUtil.instance.px_12,
                          right: PxUtil.instance.px_12,
                          top: PxUtil.instance.px_10,
                          bottom: PxUtil.instance.px_10,
                        ),
                        defaultCont: model.reports??'',
                        hintText: '${StringUtil.instance.Describe_more_clear_reporting_information}',
                        hintFontColor: ColorUtil.instance.color_half_white,
                        height: PxUtil.instance.px_148,
                        maxLength: 200,
                        isShowCounter: true,
                        borderColor: ColorUtil.instance.color_transparent,
                        onChanged: (value) => model.inputChange(value),
                      ),
                    ),
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(
                    top: PxUtil.instance.screenHeight/8,
                    left: PxUtil.instance.px_15,
                    right: PxUtil.instance.px_15,
                  ),
                  child: MainGradientButton(
                    onPressed: ()=>model.submit(),
                    txt: StringUtil.instance.Submit,
                  ),
                ),
              ],
            ),
          );
        }
    );
  }

  _buildTagItemUi(ReportViewModel model, int index) {
    return Container(
      child: Row(
        children: [
          ImagesUtil.loadAssetImage(
              model.selectedTagIndex.value==index?
              DrawableUtil.instance.icon_selected:DrawableUtil.instance.icon_unselected,
              width: PxUtil.instance.px_16
          ),
          SizedBox(width: PxUtil.instance.px_5,),
          Expanded(child: Text(
              model.reportTags[index],
            style: TextStyle(
              color: ColorUtil.instance.color_white,
              fontSize: PxUtil.instance.px_12
            ),
          ))
        ],
      ),
    );
  }
}
